import os 
if os.name == 'nt':
    os.chdir("C:\\federated_malware\\Project")
    print ("cwd",os.getcwd())#获得当前目录
    print ("工作目录",os.path.abspath('.'))#获得当前工作目录
    print ("工作目录",os.path.abspath(os.curdir))#获得当前工作目录


filelist = []
filepath = './results/'
# walk是为了遍历子目录的。一次就能多的当前目录下所有的files
for root,dirs,files in os.walk(filepath):
    filelist=files
    break

for file in filelist:
    print(file)

print(filelist)


import torch 
import matplotlib.pyplot as plt
for i,file in enumerate(filelist):
    fig = plt.figure(i,figsize=(12,12),dpi=100)
    j=1
    data_dict = torch.load(filepath+file)
    print(file)
    if 'test_accuracy' in data_dict:
        plt.subplot(3,2,j)
        plt.plot(data_dict['test_accuracy'])
        plt.title('test accuracy')
        plt.xlabel('round')
        plt.ylabel('acc')
        plt.tight_layout()
        j+=1
    
    if 'train_loss' in data_dict:
        plt.subplot(3,2,j)        
        plt.plot(data_dict['train_loss'])
        plt.title('train loss')
        plt.xlabel('round')
        plt.ylabel('loss')
        plt.tight_layout()
        j+=1
    
    if 'train_accuracy' in data_dict:
        plt.subplot(3,2,j)
        plt.plot(data_dict['train_accuracy'])
        plt.title('train accuracy')
        plt.xlabel('round')
        plt.ylabel('accuracy')
        plt.tight_layout()
        j+=1
    
    if 'information_increase_matrix' in data_dict:
        plt.subplot(3,2,j)
        plt.bar(range(len(data_dict['information_increase_matrix'])),data_dict['information_increase_matrix'])
        plt.title('information_increase_matrix')
        plt.xlabel('client number')
        plt.ylabel('contribution')
        plt.tight_layout()
        j+=1
    
    if 'information_increase_list' in data_dict:
        plt.subplot(3,2,j)
        plt.plot(data_dict['information_increase_list'])
        plt.title('information_increase_list')
        plt.xlabel('round')
        plt.ylabel('delta information')
        plt.tight_layout()
        j+=1

    plt.show()
